package org.vectrics.recruiter.struts.tag;

/**
 * @author Mike Moore
 * @version 1.0
 */

import java.util.Properties;

import org.apache.log4j.Category;
import org.vectrics.VectricsException;
import org.vectrics.common.view.SimpleForm;
import org.vectrics.user.Person;
import org.vectrics.user.UserProfile;
import javax.servlet.http.HttpServletRequest;


public class HiddenUserEditTag extends org.vectrics.user.web.struts.UserEditTag {
	public static final long serialVersionUID = 67328631;
	
    static private Category log = Category.getInstance(HiddenUserEditTag.class);
    
    protected boolean getShowMaritalStatus(HttpServletRequest request) {
        return(true);
    }
    
    protected boolean getShowGender(HttpServletRequest request) {
        return(true);
    }
    
    protected boolean getShowKnownAs(HttpServletRequest request) {
        return(true);
    }
    
    protected boolean getShowPrefix(HttpServletRequest request) {
        return(true);
    }
    
    
    // Default is to edit the user of this web service - overrides of this class can edit other users
    protected Person getPersonToEdit(HttpServletRequest request) throws VectricsException {
        log.debug("getUserToEdit() - called");
        String userId = request.getParameter("user");
        String newUserParam = request.getParameter("new_user");

        Person appUser = null;
        if (newUserParam == null) {
            appUser = this.getAuthPerson();
    
            if (appUser == null) {
                log.debug("getUserToEdit() - user is null");
            }
        }
        else {
                log.debug("getUserToEdit() - creating new user");
        }
        
        return(appUser);
    }
    
    

    protected String getFormAction(HttpServletRequest request) {
        return(request.getContextPath() + "/admin/save_user.do");
    }
    
    
    protected void makeRecruitForm(HttpServletRequest request, Properties params, Properties invalidParams, UserProfile userProfile, SimpleForm form) {
/*    	
        log.debug("makeForm() called");

        log.debug("makeForm() - calling base class's makeForm() - this will create standard entry fields for users.");
        super.makeForm(request, params, invalidParams, userProfile.getUser(), form);
        try {
        
	        if (userProfile != null) {
	            log.debug("makeForm() - Add params to request so edit fields will be populated with current contact attr's.");
	            HashSet masterAttrList = new HashSet();
	            Iterator iter = userProfile.getUser().getContactInfo().getContactAttributes().iterator();
	            while (iter.hasNext()) {
	                UserAttribute attr = (UserAttribute)iter.next();
	                String paramName = SaveUserAction.HIDDEN_ATTRIBUTE_PARAM + attr.getCode(); 
	                log.debug("makeForm() - user has hidden contact attribute param: " + attr.getCode());
	                params.setProperty(paramName, attr.getValue());
	    
	                log.debug("makeForm() - Add this attribute to the list of editable attributes if the default configuration doesn't list it.");
	                ConfigAttribute cfgAttr = RecruitConfig.getInstance().findHiddenContactAttribute(attr.getCode());
	                if (cfgAttr == null) {
	                    log.debug("makeForm() - attribute not part of configuration, forcing edit box to display.");
	                    cfgAttr = new ConfigAttribute();
	                    cfgAttr.setName(attr.getName());
	                    cfgAttr.setCode(attr.getCode());
	                    masterAttrList.add(cfgAttr);
	    
	                    // Add param to query so name can be properly stored with attribute.
	                    String nameParamName = SaveUserAction.HIDDEN_NAME_PARAM + attr.getCode();
	                    params.setProperty(nameParamName, attr.getName());
	                }
	            }
	    
	            masterAttrList.addAll(RecruitConfig.getInstance().getHiddenContactAttributes());
	            
	            iter = masterAttrList.iterator();
	            while (iter.hasNext()) {
	                ConfigAttribute attr = (ConfigAttribute)iter.next();
	                form.addBlankRow();
	            //    form.makeEditRow(SaveUserAction.HIDDEN_ATTRIBUTE_PARAM + attr.getCode(), attr.getName(), false);
	                
	                TextArea textArea = new TextArea();
	                textArea.setRows(3);
	                textArea.setCols(60);
	                textArea.setStyle("font-family:verdana,arial,sans serif;font-size=10px");
	                String paramName = SaveUserAction.HIDDEN_ATTRIBUTE_PARAM + attr.getCode(); 
	                if (request.getParameter(paramName) != null) {
	                    log.debug("makeForm() - found previous value for hidden info field");
	                    textArea.addElement(request.getParameter(paramName));
	                }
	                form.addTextAreaRow(attr.getName(), SaveUserAction.HIDDEN_ATTRIBUTE_PARAM + attr.getCode(), textArea, false);
	                
	            }
	        }
		}
		catch (Exception ve) {
			log.error("Exception in makeRecruitForm()", ve);
		}
*/	        
    }

}
